package com.chhuang.ewcrm.utils;

import javafx.scene.control.TextFormatter;
import org.apache.commons.lang3.StringUtils;

import java.util.function.UnaryOperator;

/**
 * @author chhuang
 * @create 2020-10-31-14:23
 */
public class LengthTextFilter implements UnaryOperator<TextFormatter.Change> {
    protected int maxLength=15;
    public LengthTextFilter(){};
    public LengthTextFilter(int maxLength){
        this.maxLength = maxLength;
    }
    @Override
    public TextFormatter.Change apply(TextFormatter.Change change) {
        if(change!=null){
            String text = change.getControlNewText();
            if(StringUtils.isEmpty(text) || text.length()<=maxLength){
                return change;
            }
        }
        return null;
    }
}
